package cc.sheji;

import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig;

import com.wechat.pay.java.service.payments.nativepay.NativePayService;
import com.wechat.pay.java.service.payments.nativepay.model.Amount;
import com.wechat.pay.java.service.payments.nativepay.model.PrepayRequest;
import com.wechat.pay.java.service.payments.nativepay.model.PrepayResponse;

/**
 * Native 支付下单为例
 */
public class QuickStart {

    /**
     * 商户号
     */
    public static String merchantId = "1612407211";

    /**
     * 商户API私钥路径
     */
    public static String privateKeyPath = "C:\\Users\\tom\\apiclient_key.pem";
    /**
     * 商户证书序列号
     */
    public static String merchantSerialNumber = "598F16A99583B2A92C1C48F5FC15C5C36615C786";
    /**
     * 商户APIV3密钥
     */
    public static String apiV3key = "al35wx22kf28ny1908830912et13301x";


    public static void task1() {
        Config config =
                new RSAAutoCertificateConfig.Builder()
                        .merchantId(merchantId)
                        .privateKeyFromPath(privateKeyPath)
                        .merchantSerialNumber(merchantSerialNumber)
                        .apiV3Key(apiV3key)
                        .build();
        // 构建service
        NativePayService service = new NativePayService.Builder().config(config).build();
        // request.setXxx(val)设置所需参数，具体参数可见Request定义
        PrepayRequest request = new PrepayRequest();
        Amount amount = new Amount();
        amount.setTotal(1);
        request.setAmount(amount);
        request.setAppid("wx85dd784a1d6ddc9d");
        request.setMchid("1612407211");
        request.setDescription("测试商品标题");
        request.setNotifyUrl("http://47.122.57.26:8080/api/v1/pay/wx");
        request.setOutTradeNo("out_trade_no_"+System.currentTimeMillis());
        //   调用下单方法，得到应答
        PrepayResponse response = service.prepay(request);
        // 使用微信扫描 code_url 对应的二维码，即可体验Native支付
        System.out.println(response.getCodeUrl());
        System.out.println(response);


    }



    public static void main(String[] args) {

         task1();
    }
}